package BookOperation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class DelBook implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.print("请输入你要删除的书名:>");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int size = bookList.getUseSize();
        int index = -1;
            for (int i = 0; i < size; i++) {
                Book book = bookList.getBook(i);
                if (name.equals(book.getBookName())) {
                    index = 1;
                    break;
                }
            }
                for (int i = index; i < size -1; i++) {
                    Book tmp = bookList.getBook(i+1);
                    bookList.setBooks(index,tmp);
                }
                    bookList.setUseSize(size-1);
                    bookList.setBooks(size-1,null);
                    System.out.println("删除成功");
            }

    }
